<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="query.query.orderNo" clearable placeholder="请输入订单编号" />
      <el-input v-model="query.query.inStoreNo" clearable placeholder="请输入入库单号" />
      <el-input v-model="query.query.supplierName" clearable placeholder="请输入供应商名称" />
      <el-select v-model="query.query.inStoreState" clearable style="margin-right:10px;" placeholder="请选择入库状态"
        filterable @change="getdata">
        <el-option v-for="item in warehousing" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-date-picker v-model="q_p_formDate1" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="daterange"
        range-separator="-" start-placeholder="申请开始日期" end-placeholder="申请结束日期" @change="q_p_selectTimecreate" />
      <el-button type="primary" icon="el-icon-search" @click="search">
        {{ $t("table.search") }}
      </el-button>
      <el-button type="primary" icon="el-icon-plus" @click="dialogVisible = true">
        新增
      </el-button>
      <!-- <el-button type="primary" icon="el-icon-check" @click="dialogVisible = true">
        确认入库
      </el-button> -->
      <el-button @click="handleExport" type="primary" icon="el-icon-download">
        {{ $t("table.export") }}
      </el-button>
    </div>
    <el-table :data="tableData" row-key="id" highlight-current-row border
      :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }">
      <!-- <el-table-column prop="inoutStoreNo" label="申请单号" /> -->
      <el-table-column label="订单编号" prop="businessNo" />
      <el-table-column label="入库单号" prop="inoutStoreNo" />
      <el-table-column label="物料名称" prop="materialName" />
      <el-table-column label="物料编码" prop="materialNo" />
      <el-table-column prop="applyType" label="入库类型" align="center" width="80">
        <template slot-scope="{ row }">
          <span>{{ getRkApplyType(row.applyType) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="inoutStoreNum" label="入库数量" align="center" width="80" />
      <el-table-column label="入库位置" prop="fromWarehouseName" />
      <el-table-column prop="tuihuoNum" label="退货数量" />
      <el-table-column prop="tuihuoState" label="退货状态" >
        <template slot-scope="{ row }">
          <span>{{ row.applyType == 8 ? row.tuihuoState == 1 ? '已退货' : '未退货' : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商名称" prop="partnerName" />
      <el-table-column prop="inoutStoreState" label="入库状态" align="center" width="80">
        <template slot-scope="{ row: { inoutStoreState } }">
          {{ inoutStoreState == 0 ? "待入库" : "已入库" }}
        </template>
      </el-table-column>
      <el-table-column label="订单日期" prop="orderDate">
        <template slot-scope="{ row }">
          <span>{{
            row.orderDate | parseTime("{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库申请时间" prop="applyTime">
        <template slot-scope="{ row }">
          <span>{{
            row.applyTime | parseTime("{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="确认入库时间" prop="replyTime">
        <template slot-scope="{ row }">
          <span>{{
            row.replyTime | parseTime("{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.actions')" align="center" width="320">
        <template slot-scope="{ row, $index }">
          <!-- <el-button type="primary" size="mini" 
            @click="handleUpdate(row, $index)">
            {{ $t('table.edit') }}
          </el-button> -->
          <el-button type="primary" size="mini" @click="handleClick(row, 1)" :disabled="row.inoutStoreState == '1'">
            {{row.applyType == 8 ? '退货确认' : '入库确认'}}
          </el-button>
          <el-button type="primary" size="mini" @click="handleClick(row, 2)" :disabled="row.inoutStoreState != '1'">
            生成采购收货单
          </el-button>
          <el-button type="danger" :disabled="row.inoutStoreState != '0'" size="mini" @click="handleDel(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total" :total="total" :page.sync="query.pageIndex" :limit.sync="query.pageSize"
      @pagination="getInfo" />
    <el-dialog width="80%" :close-on-click-modal="false" :visible.sync="dialogVisible" @closed="handleCloseRk"
      title="入库">
      <el-form ref="ruleForm" :rules="rules" :model="project" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库类型" prop="applyType">
              <el-select style="width: 100%;" v-model="project.applyType" filterable placeholder="请选择入库类型" clearable>
                <el-option v-for="item in applyTypeList" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库商品" prop="materialId">
              <el-select style="width: 100%;" v-model="project.materialId" filterable placeholder="请选择入库商品" clearable
                @change="getWmsStockChangeInStoreList">
                <el-option v-for="item in materialList" :key="item.id" :label="item.materialName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="!project.applyType || project.applyType === '4'">
          <el-col :span="12">
            <el-form-item label="源头仓库" prop="fromWarehouseId">
              <el-select style="width: 100%;" v-model="project.fromWarehouseId" @change="getWmsStockChangeInStoreList"
                filterable placeholder="请选择源头仓库" clearable>
                <el-option v-show="item.id !== project.toWarehouseId && item.state == '1'
                  " v-for="item in warehouseList" :key="item.id" :label="item.warehouseName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="目标仓库" prop="toWarehouseId">
              <el-select style="width: 100%;" v-model="project.toWarehouseId" filterable placeholder="请选择目标仓库"
                clearable>
                <el-option v-show="project.fromWarehouseId !== item.id && item.state == '1'
                  " v-for="item in warehouseList" :key="item.id" :label="item.warehouseName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-else>
          <el-col :span="12">
            <el-form-item label="目标仓库" prop="fromWarehouseId">
              <el-select style="width: 100%;" v-model="project.fromWarehouseId" filterable placeholder="请选择源头仓库"
                clearable @change="getWmsStockChangeInStoreList">
                <el-option v-show="item.id !== project.toWarehouseId && item.state == '1'
                  " v-for="item in warehouseList" :key="item.id" :label="item.warehouseName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table v-if="project.applyType === '4'" :data="rkTableData" row-key="id" highlight-current-row border
        @selection-change="rkHandleSelectionChange" :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }" ref="multipleTable">
        <el-table-column type="selection" width="55" :selectable="selectableStatus" />
        <el-table-column prop="warehouseName" label="仓库" width="220" />
        <el-table-column prop="inoutStoreNo" label="入库单号" width="160" />
        <el-table-column prop="materialNo" label="商品编码" />
        <el-table-column prop="materialName" label="商品名称" />
        <el-table-column prop="changeType" label="入库类型">
          <template slot-scope="{ row }">
            <span>{{ getRkApplyType(row.changeType) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="changeNum" label="入库数量" />
        <el-table-column prop="leftNum" label="剩余数量" />
        <el-table-column prop="outStoreNum" label="入库数量" width="150">
          <template slot-scope="{row}">
            <el-input clearable v-model.trim="row.inoutStoreNum" size="small"
              @input="row.inoutStoreNum = row.inoutStoreNum.replace(/[^\d|\.]/g, '')" placeholder="请输入入库数量" />
          </template>
        </el-table-column>
        <el-table-column prop="changeTime" label="入库日期" width="160">
          <template slot-scope="{row}">
            <span>{{ row.changeTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="rkTotal && project.applyType == '4'" :total="rkTotal" :page.sync="rkQuery.pageIndex"
        :limit.sync="rkQuery.pageSize" @pagination="getWmsStockChangeInStoreList" />
      <el-table v-if="project.applyType === '6'" :data="generateTableData" row-key="id" highlight-current-row border
        :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }">
        <el-table-column prop="inoutStoreNum" label="入库数量">
          <template slot-scope="{ row, $index }">
            <el-input v-model="row.inoutStoreNum" :disabled="generateId" placeholder="请输入入库数量"
              onkeyup="value=value.replace(/[^\d.]/g,'')" />
          </template>
        </el-table-column>
        <el-table-column prop="batchNumber" label="批次号">
          <template slot-scope="{ row, $index }">
            <el-input v-model="row.batchNumber" :disabled="generateId" placeholder="请输入批次号" />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="{ row, $index }">
            <el-button v-if="$index == 0" type="primary" icon="el-icon-circle-plus-outline" @click="addGenerate"
              circle></el-button>
            <el-button v-if="$index > 0" type="danger" icon="el-icon-remove-outline" circle
              @click="minusGenerate($index)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="dialogVisible = false">
          {{ $t("permission.cancel") }}
        </el-button>
        <el-button type="primary" @click="submit">
          {{ $t("permission.save") }}
        </el-button>
      </div>
    </el-dialog>
    <el-dialog width="600px" @closed="handleClose" :close-on-click-modal="false" :visible.sync="rkDialogVisible"
      :title="rkForm.applyType == 8 ? '退货确认' : '确认入库'">
      <el-form ref="rkRuleForm" :rules="rkRules" :model="rkForm" label-width="80px">
        <el-form-item v-if="rkForm.applyType != 8" label="仓库" prop="warehouseId">
          <el-select style="width: 100%;" v-model="rkForm.warehouseId" filterable placeholder="请选择仓库" clearable>
            <el-option v-for="item in rkTableData" :key="item.warehouseId" :label="item.warehouseName"
              :value="item.warehouseId" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="rkForm.applyType != 8" label="入库单号" prop="inStoreNo">
          <el-input v-model="rkForm.inStoreNo" size="small" placeholder="请输入入库单号" />
        </el-form-item>
        <el-form-item v-if="rkForm.applyType == 8" label="退货单号" prop="huiHuoBillNo">
          <el-input v-model="rkForm.huiHuoBillNo" size="small" placeholder="请输入退货单号" />
        </el-form-item>
        <el-table v-if="rkForm.applyType != 8" :data="rkForm.sureRkTable" row-key="id" highlight-current-row border
          :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }">
          <el-table-column prop="inoutStoreNum" label="入库数量" />
          <el-table-column prop="batchNumber" label="批次号" :render-header="renderRequiredHeader('批次号')">
            <template slot-scope="{row}">
              <el-input v-model="row.batchNumber" clearable placeholder="请输入批次号" />
            </template>
          </el-table-column>
        </el-table>
        <!-- <el-form-item label="批次号" prop="batchNumber">
          <el-input v-model="rkForm.batchNumber" clearable placeholder="请输入批次号" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="rkDialogVisible = false">
          {{ $t("permission.cancel") }}
        </el-button>
        <el-button type="primary" @click="rkSubmit">
          {{ $t("permission.save") }}
        </el-button>
      </div>
    </el-dialog>
    <el-dialog width="80%" :close-on-click-modal="false" :visible.sync="thDialogVisible" title="退货">
      <el-table :data="thTableData" row-key="id" highlight-current-row border
        @selection-change="thHandleSelectionChange" :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }" ref="multipleTable">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="warehouseName" label="仓库" width="220" />
        <el-table-column prop="inoutStoreNo" label="入库单号" width="160" />
        <el-table-column prop="materialNo" label="商品编码" />
        <el-table-column prop="materialName" label="商品名称" />
        <el-table-column prop="changeType" label="入库类型">
          <template slot-scope="{ row }">
            <span>{{ getRkApplyType(row.changeType) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="changeNum" label="入库数量" />
        <el-table-column prop="leftNum" label="剩余数量" />
        <el-table-column prop="inoutStoreNum" label="退货数量" width="150">
          <template slot-scope="{row}">
            <el-input clearable v-model.trim="row.inoutStoreNum" size="small"
              @input="row.inoutStoreNum = row.inoutStoreNum.replace(/[^\d|\.]/g, '')" placeholder="请输入退货数量" />
          </template>
        </el-table-column>
        <el-table-column prop="changeTime" label="入库日期" width="160">
          <template slot-scope="{row}">
            <span>{{ row.changeTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="thDialogVisible = false">
          {{ $t("permission.cancel") }}
        </el-button>
        <el-button type="primary" @click="thSubmit">
          {{ $t("permission.save") }}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import {
  pageInstoreList,
  inStoreConfirm,
  tuiHuoConfirm,
  codeWarehousePageList,
  codeMaterialListAll,
  wmsStoreApplyAdd,
  wmsStockWareHouseList,
  wmsStockChangeInStoreList,
  wmsStockApplyChangeList,
  wmsStockApplyExportInStoreExcel,
  wmsStoreApplyBatchNumberList,
  wmsStoreApplyGeneralGoodsReceivedNote,
  wmsStoreApplyDel
} from "@/api/qmsQualityManagement";
import { downfile } from "@/utils";

const project = {
  id: 0,
  close: "",
  referCost: "",
  acceptAppeal: 0,
  appeal: 0
};

export default {
  name: "Project",
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      generateTableData: [{
        inoutStoreNum: '',
        batchNumber: ''
      }],
      applyTypeList: [{
        label: '调拨入库',
        value: '4'
      }, {
        label: '其他入库',
        value: '6'
      }],
      q_p_formDate1: [],
      sureRkTable: [],
      rkDialogVisible: false,
      rkTableData: [],
      rkForm: {
        batchNumber: ''
      },
      warehousing: [
        {
          label: "待入库",
          value: "0"
        },
        {
          label: "已入库",
          value: "1"
        }
      ],
      solutionList: [
        {
          value: "索赔"
        },
        {
          value: "补货"
        },
        {
          value: "补货并索赔"
        },
        {
          value: "返工返修"
        }
      ],
      rules: {
        applyType: [
          { required: true, message: "请选择入库类型", trigger: "change" }
        ],
        materialId: [
          { required: true, message: "请选择入库商品", trigger: "change" }
        ],
        inoutStoreNum: [
          { required: true, message: "请输入入库数量", trigger: "blur" }
        ],
        fromWarehouseId: [
          { required: true, message: "请选择源头仓库", trigger: "blur" }
        ],
        toWarehouseId: [
          { required: true, message: "请选择目标仓库", trigger: "blur" }
        ]
      },
      rkRules: {
        warehouseId: [
          { required: true, message: "请选择仓库", trigger: "change" }
        ],
        batchNumber: [
          { required: true, message: "请输入批次号", trigger: "blur" }
        ],
        inStoreNo:[
          { required: true, message: "请输入入库单号", trigger: "blur" }
        ],
        huiHuoBillNo:[
          { required: true, message: "请输入退货单号", trigger: "blur" }
        ]
      },
      list: [],
      query: {
        pageIndex: 1,
        pageSize: 20,
        query: {
          inOut: 1,
          startDate: null,
          endDate: null
        }
      },
      total: 0,
      dialogVisible: false,
      project: {},
      tableData: [],
      warehouseList: [],
      warehousequery: {
        pageIndex: 1,
        pageSize: 1000000,
        query: {}
      },
      materialList: [],
      rkSelectedListData: [],
      rkQuery: {
        pageIndex: 1,
        pageSize: 10
      },
      thDialogVisible: false,
      thTableData: [],
      thId: null,
      materialId: null,
      thWarehouseId: null,
      thSelectedListData: []
    };
  },
  computed: {},
  mounted() {
    this.getday()
    this.getInfo();
    this.getUserPage();
    this.getCodeMaterialListAll();
  },
  methods: {
    renderRequiredHeader(label) {
      return (h) => {
        return h('div', { class: 'required-header' }, [
          h('span', { style: { color: 'red', marginRight: '4px' } }, '*'),
          h('span', label)
        ]);
      }
    },
    async handleExport() {
      try {
        const { query } = this.query
        await wmsStockApplyExportInStoreExcel(
          query
        )
      } catch (err) {
        const reader = new FileReader();
        reader.readAsText(err);
        reader.onload = (event) => {
          const resultString = reader.result; // 这里就是转换后的字符串
          if (resultString.includes('code') && resultString.includes('isSuccess')) {
            this.$message.error(JSON.parse(resultString).message)
          } else {
            downfile('入库.xlsx', err);
          }
        }
      }
    },
    thHandleSelectionChange(e) {
      this.thSelectedListData = [];
      e.forEach(item => {
        this.thSelectedListData.push(item);
      });
    },
    async thSubmit() {
      if (!this.thSelectedListData.length) {
        this.$message.warning("请至少选择一条出库记录！");
        return;
      }
      try {
        let batchVoList = []
        this.thSelectedListData.forEach(item => {
          if (!item.inoutStoreNum) {
            this.$message.error('请输入退货数量！')
            throw new Error()
          }
          batchVoList.push({
            changeId: item.id,
            batchNumber: item.batchNumber,
            inoutStoreNum: item.inoutStoreNum
          })
        })
        await wmsStoreApplyAdd({
          applyType: '9',
          materialId: this.materialId,
          fromWarehouseId: this.thWarehouseId,
          batchVoList
        })
        this.$message.success('操作成功！')
        this.thDialogVisible = false
        this.getInfo()
      } catch (err) {

      }
    },
    async getWmsStockApplyChangeList() {
      this.thTableData = await wmsStockApplyChangeList(this.thId, '1')
      if (this.thTableData.length) {
        this.thTableData.forEach(item => {
          this.$set(item, 'inoutStoreNum', item.changeNum)
        })
      }
    },
    handleCancelOrder(row) {
      this.thId = row.idStr
      this.materialId = row.materialId
      this.thWarehouseId = row.warehouseId
      this.getWmsStockApplyChangeList()
      this.thDialogVisible = true
    },
    handleCloseRk() {
      this.project = {}
      this.generateTableData = [{
        inoutStoreNum: '',
        batchNumber: ''
      }]
      this.$refs['ruleForm'] && this.$refs['ruleForm'].resetFields();
    },
    getRkApplyType(val) {
      if (val == 1) {
        return "销售出库";
      } else if (val == 2) {
        return "采购入库";
      } else if (val == 4) {
        return "调拨入库";
      } else if (val == 5) {
        return "调拨出库";
      } else if (val == 6) {
        return "其他入库";
      } else if (val == 7) {
        return "其他出库"
      } else if (val == 8) {
        return "销售退货入库";
      } else if (val == 9) {
        return "采购退货出库";
      }
    },
    rkHandleSelectionChange(e) {
      this.rkSelectedListData = [];
      e.forEach(item => {
        this.rkSelectedListData.push(item);
      });
    },
    async getWmsStockChangeInStoreList() {
      const { materialId, fromWarehouseId } = this.project
      if (!materialId || !fromWarehouseId) return
      const { records, total } = await wmsStockChangeInStoreList({
        ...this.rkQuery,
        query: {
          materialId: this.project.materialId,
          warehouseId: this.project.fromWarehouseId
        }
      })
      records.forEach(item => {
        this.$set(item, 'inoutStoreNum', item.leftNum)
      })
      this.rkTotal = total
      this.rkTableData = records
    },
    getday() {
      // const currDate = new Date().toLocaleDateString()// 2020/11/6
      // const arrs = currDate.split('/')
      // const arrs1 = arrs.join('-')
      // this.query.query.beginDate = this.query.query.endDate = arrs1
      // this.q_p_formDate1 = [arrs1, arrs1]
      const currDate = new Date().toLocaleDateString()// 2020/11/6
      const arrs = currDate.split('/')
      const arrs1 = arrs.join('-')
      const yy = parseInt(arrs[0]);
      const mm = parseInt(arrs[1]);
      const dd = parseInt(arrs[2]);
      const pdStr = new Date(yy, mm - 1, 1).toLocaleDateString().split('/').join('-');
      this.query.query.startDate = pdStr
      this.query.query.endDate = arrs1
      this.q_p_formDate1 = [pdStr, arrs1]
    },
    q_p_selectTimecreate(val) {
      const { query } = this.query
      if (val) {
        query.startDate = val[0]
        query.endDate = val[1]
      } else {
        query.startDate = query.endDate = ''
      }
    },
    handleClose() {
      this.rkForm = {}
    },
    validateInteger(value) {
      if (value < 1) {
        this.project.inoutStoreNum = 1;
      } else {
        const numValue = parseInt(value, 10);
        if (!Number.isNaN(numValue)) {
          this.project.inoutStoreNum = numValue;
        } else {
          this.project.inoutStoreNum = 1;
        }
      }
    },
    async getCodeMaterialListAll() {
      this.materialList = await codeMaterialListAll();
    },
    async getUserPage() {
      const { records } = await codeWarehousePageList(this.warehousequery);
      this.warehouseList = records;
    },
    handleDel({id}){
      this.$confirm("确认删除入库明细?", "警告", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            wmsStoreApplyDel(id).then(res => {
              this.getInfo();
              this.$message.success("删除成功");
            });
          });
    },
    async handleClick({ idStr, materialId,applyType }, val) {
      if (val == 1) {
        this.$set(this.rkForm, 'idStr', idStr)
        this.$set(this.rkForm, 'applyType', applyType)
        this.rkTableData = await wmsStockWareHouseList(materialId, '1')
        const data = await wmsStoreApplyBatchNumberList(idStr)
        this.rkForm.sureRkTable = data
        // this.$set(this.rkForm, 'inoutStoreNum', data[0].inoutStoreNum)
        this.rkDialogVisible = true
      } else {
        try {
          await wmsStoreApplyGeneralGoodsReceivedNote(idStr)
        } catch (err) {
          const reader = new FileReader();
          reader.readAsText(err);
          reader.onload = (event) => {
            const resultString = reader.result; // 这里就是转换后的字符串
            if (resultString.includes('code') && resultString.includes('isSuccess')) {
              this.$message.error(JSON.parse(resultString).message)
            } else {
              downfile(`采购收货单.xlsx`, err)
            }
          }
        }
      }
    },
    async rkSubmit() {
      this.$refs['rkRuleForm'].validate((valid) => {
        if (valid) {
          try {
            this.rkForm.sureRkTable.forEach(item => {
              if (!item.batchNumber) {
                this.$message.error("请输入批次号！");
                throw new Error();
              }
            })
            this.$confirm("确认入库, 是否继续?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(async () => {
              let params = {
                id: this.rkForm.idStr,
                warehouseId: this.rkForm.warehouseId,
                inStoreList: this.rkForm.sureRkTable,
                inStoreNo:this.rkForm.inStoreNo
              }
              if(this.rkForm.applyType == 8){
                params.huiHuoBillNo = this.rkForm.huiHuoBillNo
                await tuiHuoConfirm(params)
              }else{
                await inStoreConfirm(params);
              }
              this.getInfo();
              this.$message.success("操作成功！");
              this.rkDialogVisible = false
            });
          } catch (err) {

          }
        }
      })
    },
    minusGenerate(index) {
      this.generateTableData.splice(index, 1)
    },
    addGenerate() {
      if (!this.generateTableData[this.generateTableData.length - 1].inoutStoreNum) {
        this.$message.error('请输入入库数量')
        return
      }
      if (!this.generateTableData[this.generateTableData.length - 1].batchNumber) {
        this.$message.error('请输入批次号')
        return
      }
      this.generateTableData.push({
        inoutStoreNum: '',
        batchNumber: ''
      })
    },
    submit() {
      this.$refs["ruleForm"].validate(async valid => {
        if (valid) {
          try {
            const {
              materialId,
              fromWarehouseId,
              toWarehouseId,
              applyType
            } = this.project;
            if (applyType == '6') {
              if (!this.generateTableData[this.generateTableData.length - 1].inoutStoreNum || !this.generateTableData[this.generateTableData.length - 1].batchNumber) {
                this.$message.error('请将数据填写完成！')
                return
              }
            }
            let params = {
              applyType,
              materialId,
              fromWarehouseId,
              batchVoList: []
            }
            if (applyType == '4') {
              params.toWarehouseId = toWarehouseId
              this.rkSelectedListData.forEach(item => {
                if (!item.inoutStoreNum) {
                  this.$message.warning("入库数量不能为空！");
                  throw new Error()
                }
                params.batchVoList.push({
                  changeId: item.id,
                  batchNumber: item.batchNumber,
                  inoutStoreNum: item.inoutStoreNum
                })
              })
            } else {
              params.batchVoList = this.generateTableData
            }
            await wmsStoreApplyAdd(params);
            this.dialogVisible = false;
            this.getInfo();
            this.$message.success("操作成功！");
          } catch (err) {

          }
        }
      });
    },
    handleUpdate(row, $index) {
      this.dialogVisible = true;
    },
    search() {
      this.query.pageIndex = 1;
      this.getInfo();
    },
    getInfo() {
      pageInstoreList(this.query).then(res => {
        const { records, total } = res;
        this.tableData = records;
        this.total = total;
      });
    }
  }
};
</script>

<style scoped>
.addinput /deep/ .el-input__inner {
  border: none;
  background: #f5f7fa;
}

.addinput /deep/ .el-textarea__inner {
  border: none;
  background: #f5f7fa;
}

.downfile {
  text-decoration: underline;
  color: blue;
}
</style>
